<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>发布岗位</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<style>
    #area-picker {
        position: absolute;
    }
</style>

<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">岗位名</label>
        <div class="layui-input-block">
            <input type="text" name="jname" id="jname" lay-verify="required" lay-reqtext="岗位名不能为空" placeholder="请输入岗位名" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">岗位类型</label>
        <div class="layui-input-block">
            <input type="text"  id="jtype" lay-verify="required" lay-reqtext="" readonly="readonly" placeholder="请输入岗位名" value="" class="layui-input">
            <tip></tip>
        </div>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label">薪资范围</label>
        <div class="layui-input-block">
            <div class="layui-input-inline" style="width: 100px;">
                <input type="text" name="minSalary" id="minSalary" placeholder="￥" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid">-</div>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="text" name="maxSalary" id="maxSalary" placeholder="￥" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>


    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">工作地址</label>
        <div class="layui-input-block">
            <input type="text" name="workAddress" id="workAddress" lay-verify="required" lay-reqtext="工作地址不能为空" placeholder="请输入工作地址" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">招聘人数</label>
        <div class="layui-input-inline" style="width: 100px;">
            <input type="text" name="count" id="count" lay-verify="required" lay-reqtext="招聘人数不能为空" placeholder="招聘人数" value="" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">岗位描述</label>
        <div class="layui-input-block">
            <textarea id="description" name="description" class="layui-textarea" placeholder="请输入备注信息"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">招聘要求</label>
        <div class="layui-input-block">
            <textarea id="requirement" name="requirement" class="layui-textarea" placeholder="请输入备注信息"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveBtn">修改</button>
        </div>
    </div>
</div>
<script src="../../js/commons.js"></script>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../js/jquery-3.6.0.js"></script>
<script>
    var jid= GetQueryString("jid"); // "add"

    //封装GetQueryString()方法来获取URL后面的value值
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null)
            return decodeURI(r[2]);
        return null;
    }


    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        $.ajax({
            url:  URL + "recruiter/job/selectOneJob",
            data: {jid:jid},
            success: function (result){
                var $jname = $("#jname");
                if (result.code == 0){
                    $("#jname").attr("placeholder",result.data.jname),
                        $("#jtype").val(result.data.jobType.jtname),
                        $("#minSalary").attr("placeholder",result.data.minSalary),
                        $("#maxSalary").attr("placeholder",result.data.maxSalary),
                        $("#workAddress").attr("placeholder",result.data.workAddress),
                        $("#count").attr("placeholder",result.data.count),
                        $("#description").attr("placeholder",result.data.description),
                        $("#requirement").attr("placeholder",result.data.requirement),

                        form.render();//修改了表单中的数据需要重新渲染表格
                }

            }
        })
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            data.field.jid=jid
            data.field
            console.log(data)
            $.ajax({
                url : URL + "recruiter/job/updateJob",
                data: data.field,
                headers: {"token":localStorage.getItem("token")},
                type: "post",
                success: function (result){
                    if (result.code == 2){

                    } else if (result.code == 0){//发布成功
                        layer.msg(result.msg,function (){
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                            window.location.href = "job.html";

                        })

                    }
                }
            });
            return false;
        });

    });
</script>
</body>
</html>